package com.microsec.iot.utils;

import java.util.HashMap;
import java.util.Map;

public class CommandUtil {

	private static HttpsUtil httpsUtil = new HttpsUtil();
	private static String accessToken ;
	private static String appId = Constant.APPID;
	
	static{
		try {
			httpsUtil.initSSLConfigForTwoWay();
			accessToken = LoginUtil.login(httpsUtil);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static String sendCommand(String deviceId,String commandUrl){
		//please replace the deviceId, when you use the demo.
        commandUrl = (commandUrl + "/" +deviceId);
                
        Map<String, String> header = new HashMap<>();
        header.put(Constant.HEADER_APP_KEY, appId);
        header.put(Constant.HEADER_APP_AUTH, "Bearer" + " " + accessToken);
        
        StreamClosedHttpResponse response = httpsUtil.sendCommand(commandUrl, header);

		System.out.println("DeleteDirectlyConnectedDevice, response content:");
		System.out.print(response.getStatusLine());
		System.out.println(response.getContent());
		System.out.println();
		return response.getContent();
	}
	
	public static void main(String[] args) {

				
	}

}
